home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13435 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.3 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Coding Standards
  5. Date: Mon, 25 Mar 1996 14:09:31 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <3156EF6B.2A1E@datalytics.com>
  8. References: <4hj8ek$elu@sam.inforamp.net> <4hktar$5o2@galaxy.ucr.edu> <4hmqol$97j@abacus.abasoft.co.uk> <4hsg8r$pmm@sam.inforamp.net> <4i9o6j$p4l@daisy.pgh.wec.com> <4idskb$pc1@sam.inforamp.net> <314EBD08.43BC@virtus.com> <4io2i7$n9v@sam.inforamp.net> <4isu2t$opo@janus.pec.co.nz> <4j2jot$svj@sam.inforamp.net>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Randy Charles Morin wrote:
  16. > In article <4isu2t$opo@janus.pec.co.nz>,
  17. >    JohnM@hypatia.pec.co.nz (John Marshall) wrote:
  18. > >I think you have a hard time convincing anybody of this because it's
  19. > >not true.  It seems to me that "data hiding" has to do with the actual
  20. > >*text* of clients' source code, and that recompilation is merely an
  21. > >implementation detail.
  22. > >If we had really defeated the purpose of data hiding, the statement
  23. > >would be: "if your data's type changes, then you have to rewrite all the
  24. > >clients".  This is not the case when accessors are functions which just
  25. > >happen to be inline.
  26. > >Of course, in practice, all that recompilation during development is a
  27. > >major pain.  I guess that's why people put what are going to be inline
  28. > >accessors in library.inc, and include library.inc in either library.cpp
  29. > >or (for inlining) library.hpp, dependant on whether it's a "dev make" or
  30. > >"production make" respectively.  Certainly they're implementation -- they
  31. > >don't *belong* directly in the header file.
  32. > >Seems to me that the fundamental problem is that include files are
  33. > >inherently broken compared to more automatic ways of managing the required
  34. > >information.  Alas.
  35. > Great, so your code is object oriented, encapsulated and has data hiding.  But
  36. > your post compilation objects are not encapsulated and don't use data hiding.
  37. >  That means, that if your object data member's changes types, then you have to
  38. > make an effort to conform other objects to your changes.  If you don't have
  39. > inline accessors, then you don't have a problem.  Is this so hard to
  40. > understand?
  41. > Imagine you are a producing a commercial system for several large
  42. > corporations.  The large corporation use your hooks (sometimes inline
  43. > accessors) to add functionality that is dependant on their particular business
  44. > needs.  After shipping version 1.0 with an object of type char (inline
  45. > accessed), you ship the less buggy version 1.1 with the data type changed to
  46. > an int.  Now you have to coordinate your releases with the corporations.  If
  47. > you eliminate inline accessors, then you don't have that problem.
  48. > When you talk about having to rewrite code because you defeated data hiding,
  49. > you are limiting your scope to the problems encountered by a small development
  50. > environment.  This is not usually a problem when you are the only developer
  51. > and you don't share code, but when you are sharing code with 100s of
  52. > co-developers, you can't expect everybody to coordinate the changing of a data
  53. > type.  I hope I've convinced another.
  54.  
  55. What you describe is fine if you want to ensure that a shared 
  56. library or DLL is a plug-in replacement for the previous 
  57. version.  However, if anything else changes, the users of 
  58. version 1.1 must rebuild anyway.  In that case, the change in 
  59. the type of the private dm accessed by an inline is just one 
  60. more change.  If you're building an application, your argument 
  61. has no bearing except to reduce compilation time (which is not a 
  62. vain effort, mind you).
  63.  
  64. The tradeoffs relate to performance and recompilation.  Sure, I 
  65. can build a compilation firewall that hides my entire 
  66. implementation in data pointed to by a single dm and accessed 
  67. through no inline functions.  That ensures that data 
  68. representation and manipulation are completely hidden within the 
  69. library and have no effect on the class user.
  70.  
  71. However, my experience reveals that changes as fundamental as 
  72. the type of dm usually result in the addition or subtraction of 
  73. one or more mfs, even if private.  Having done that, you've 
  74. triggered a recompilation for the class user.  In other words, 
  75. you're as likely to require a recompilation due to I/F changes 
  76. as for representation.
  77.  
  78. OK, you can extend the firewall such that the private mfs are 
  79. implemented in the representation class.  If you do that, you 
  80. will probably put all implementation in the representation 
  81. class.  That means all public and protected mfs of the public 
  82. class only forward to the corresponding representation class' 
  83. member functions.  That sounds like a recipe for efficient 
  84. software:  make all mfs non-inline function calls through a 
  85. pointer.  Let's make it worse:  for virtual functions we have a 
  86. non-line function call, through a pointer, to a function call 
  87. through a pointer.
  88.  
  89. I have exaggerated that slightly.  Some of the representation 
  90. class' mfs can be inlined, so some of the public class' mfs can 
  91. reduce to a few pointer dereferences.  That's still not great 
  92. for performance.
  93.  
  94. And you wonder why not everyone likes your approach.
  95.  
  96. -- 
  97. Robert Stewart        | My opinions are usually my own.
  98. Datalytics, Inc.    | stew@datalytics.com
  99.